// /////////////////////////////////////////////////////////////////////////////
//
// Name:            ScriptedEvent.h
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Declaration of the ScriptedEvent class.
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

#ifndef __SCRIPTEDEVENT_H__
#define __SCRIPTEDEVENT_H__

// Include files
#include "../../dependencies.h"

#ifdef __COMPILE_WITH_ANGELSCRIPT__

#include "../../core/ReferenceCounted.h"
#include "../../core/HasEvents.h"


// ScriptedEvent class
//! Internal class for allowing AngelScript to interface with the event system.
class ScriptedEvent : public ReferenceCounted, public HasSlots
{
public:

    // Initialisation and deinitialisation
    //! Constructor (EventManager)
    //! @param object        Reference to the AngelScript object that wants to connect to a signal.
    //! @param function      Name of the function to call when the event is emitted.
    ScriptedEvent(asIScriptObject *object, const std::string &function);
    //! Deconstructor
    ~ScriptedEvent();

    // Events
    //! Handles the emitted event.
    void onEvent(void *p);
    //! Handles event disconnects.
    void onDisconnect(void *p);

private:

    // Private members
    asIScriptObject *mObject;
    asIScriptContext *mContext;

    std::string mFunction;
};

#endif // __COMPILE_WITH_ANGELSCRIPT__

#endif
